'''
Created on 2010-2-8

@author: summit
'''
import wx
import wx.lib.agw.fourwaysplitter as FWS

from vtk.wx.wxVTKRenderWindowInteractor import *

class wxFWSVTKPageView(wx.Panel):
    '''
    wxFWSVTKPageView is used Advanced Generic Widget to Four
    Way Splitter the vtk View. This fix some wxVTKPageView 
    bug which could not synchronization move the view.
    '''
    __viewInteractor1 = None
    __viewInteractor2 = None
    __viewInteractor3 = None
    __viewInteractor4 = None
    __splitter = None

    def __init__(self, parent):
        '''
        Constructor
        '''
        wx.Panel.__init__(self, parent)
        
       
        # create splitter
        self.__splitter = FWS.FourWaySplitter(self, style=wx.SP_LIVE_UPDATE)
        
        # create four view
        style = wx.WANTS_CHARS or wx.NO_FULL_REPAINT_ON_RESIZE
        self.__viewInteractor1 = wxVTKRenderWindowInteractor(self.__splitter, wx.ID_ANY, style=style)
        self.__viewInteractor2 = wxVTKRenderWindowInteractor(self.__splitter, wx.ID_ANY, style=style)
        self.__viewInteractor3 = wxVTKRenderWindowInteractor(self.__splitter, wx.ID_ANY, style=style)
        self.__viewInteractor4 = wxVTKRenderWindowInteractor(self.__splitter, wx.ID_ANY, style=style)
   
        self.__splitter.AppendWindow(self.__viewInteractor1)
        self.__splitter.AppendWindow(self.__viewInteractor2)
        self.__splitter.AppendWindow(self.__viewInteractor3)
        self.__splitter.AppendWindow(self.__viewInteractor4)
        
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(self.__splitter, 1, wx.EXPAND)
        self.SetSizer(sizer)
        
        # bind the splitter-sash's event
        self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED, self.OnSashChanged)
        self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGING, self.OnSashChanging)
        
    def GetSashIdx(self, event):
        if event.GetSashIdx() == wx.HORIZONTAL:
            idx = "Horizontal"
        elif event.GetSashIdx() == wx.VERTICAL:
            idx = "Vertical"
        else:
            idx = "Horizontal & Vertical"
        return idx
    
    def OnSashChanging(self, event):
#        idx = self.GetSashIdx(event)
#        pos = event.GetSashPosition()
        pass
    
    def OnSashChanged(self, event):
        pass
    
    def ExpandWindow(self, selection):
        self.__splitter.SetExpanded(selection-1)
        
    def SwapWindow(self, selection1, selection2):
        win1 = self.__splitter.GetWindow(0)
        win2 = self.__splitter.GetWindow(2)
        self.__splitter.ExchangeWindows(win1, win2)
        
    def SetLiveUpdate(self, enable):
        if enable:
            self.__splitter.SetWindowStyle(wx.SP_LIVE_UPDATE)
        else:
            self.__splitter.SetWindowStyle(0)
    
    # set/get/property methods are auto-generater by eclipse
    def getViewInteractor1(self):
        return self.__viewInteractor1


    def getViewInteractor2(self):
        return self.__viewInteractor2


    def getViewInteractor3(self):
        return self.__viewInteractor3


    def getViewInteractor4(self):
        return self.__viewInteractor4


    def getSplitter(self):
        return self.__splitter


    def setViewInteractor1(self, value):
        self.__viewInteractor1 = value


    def setViewInteractor2(self, value):
        self.__viewInteractor2 = value


    def setViewInteractor3(self, value):
        self.__viewInteractor3 = value


    def setViewInteractor4(self, value):
        self.__viewInteractor4 = value


    def setSplitter(self, value):
        self.__splitter = value


    def delViewInteractor1(self):
        del self.__viewInteractor1


    def delViewInteractor2(self):
        del self.__viewInteractor2


    def delViewInteractor3(self):
        del self.__viewInteractor3


    def delViewInteractor4(self):
        del self.__viewInteractor4


    def delSplitter(self):
        del self.__splitter

    viewInteractor1 = property(getViewInteractor1, setViewInteractor1, delViewInteractor1, "ViewInteractor1's Docstring")

    viewInteractor2 = property(getViewInteractor2, setViewInteractor2, delViewInteractor2, "ViewInteractor2's Docstring")

    viewInteractor3 = property(getViewInteractor3, setViewInteractor3, delViewInteractor3, "ViewInteractor3's Docstring")

    viewInteractor4 = property(getViewInteractor4, setViewInteractor4, delViewInteractor4, "ViewInteractor4's Docstring")

    splitter = property(getSplitter, setSplitter, delSplitter, "Splitter's Docstring")
  
if __name__=="__main__":
    app = wx.PySimpleApp()
    frame = wx.Frame(None)
    frame.panel = wxFWSVTKPageView(frame)
    
    frame.Show(True)
    app.MainLoop()
        